﻿using Library.DataModel;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ArithmeticSimulator.View
{
    /// <summary>
    /// DifficultySettingView.xaml 的交互逻辑
    /// </summary>
    public partial class DifficultySettingView : UserControl
    {
        public DifficultySettingView()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_Build_Examination(object sender, RoutedEventArgs e)
        {
            DifficultyDataModel difficulty= new DifficultyDataModel();

            difficulty.Amount = Convert.ToInt32(this.txtTotalAmount.Text.Trim());

            if (rbRange20.IsChecked == true)
            {
                difficulty.RangeMax = 20;
            }
            else if (rbRange50.IsChecked == true)
            {
                difficulty.RangeMax = 50;
            }
            else if (rbRange100.IsChecked == true)
            {
                difficulty.RangeMax = 100;
            }

            if (rbCarryDisabled.IsChecked == true)
            {
                difficulty.Carry = CarryEnums.None;
            }
            else if (rbCarry1.IsChecked == true)
            {
                difficulty.Carry = CarryEnums.Carry1;
            }

            var enableTimeLimit = Convert.ToBoolean(this.chkEnableTimeLimit.IsChecked);
            if (enableTimeLimit)
                difficulty.TimeLimit = Convert.ToInt32(this.txtTimeLimit.Text.Trim());
            else
                difficulty.TimeLimit = -1;


            // 通知主窗口进行页面切换
            if (Window.GetWindow(this) is MainWindow mainWindow)
            {
                mainWindow.SwitchToExaminationPage(difficulty);
            }
        }
    }
}
